'use strict';


import * as React from 'react'

const {AsyncStorage} = require('react-native');
const {create} = require('dva-core');
import Routers from "./Routers";
import models from "./models/index";
import Request from "./utils/Request";
import PushHandle from "./push.ios";

const {Toast} = require('antd-mobile');
const {persistStore, autoRehydrate} = require('redux-persist');
const {Provider} = require('react-redux');
Request.init(require('./utils/api').default, false,30*1000);

const dvaApp = create({
    extraEnhancers: [autoRehydrate()],
    onError: (e) => {
        try {
            console.log('app have catch a error:', e);
        } catch (e) {
            Toast.fail(e.message, 1);
        }
    },
});

const initModels = () => {
    models.map((mode) => {
        dvaApp.model(mode);
    })
};

initModels();
dvaApp.start();


class app extends React.Component<any, any> {


    pushHand: any;

    constructor(props: any, context: any, pushHand: any) {
        super(props, context);
        console.log(props);
        PushHandle.init();
        persistStore(
            dvaApp._store,
            {storage: AsyncStorage},
            () => {}
        );
        this.pushHand = new PushHandle();
        // persistStore(dvaApp._store, {
        //         storage: AsyncStorage
        //     },
        // );
    }


    componentWillUnmount(): void {
        PushHandle.destroy()
    }

    render() {


        return (
            <Provider store={dvaApp._store}>
                <Routers/>
            </Provider>
        );
    }
}


export default app;